package com.AdvancedDemos.Learn网络编程.CS架构.useTCP4多线程实现一个服务端多个客户端;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client1 {

    public static void main(String[] args) throws IOException {
        //Client发送数据,Server接收数据
        //客户端socket
        System.out.println("客户端开启");
        Socket socket = new Socket("127.0.0.1"/*InetAddress.getLocalHost()*/, 8888);
        System.out.println("连接成功");

        Scanner sc = new Scanner(System.in);
        //发送数据
        System.out.println("发送数据");
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(outputStream);//收发要对应,都使用Data(In/Out)putStream

        while (true) {
            System.out.println("请输入要发送的数据:");
            String data = sc.nextLine();
            //获取输出字节流
            dos.writeUTF(data);
            if ("#exit".equals(data)) {
                break;
            }
        }


        socket.close();
    }
}
